package com.heimdallr.util;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Administrator on 2016/6/22.
 */
public class ThreadPoolSet {

    private HashMap<poolKind,ExecutorService> poolSet;
    private static ThreadPoolSet instance = null;
    public enum poolKind{
        danMuThreadPool,
    }
    /**
     * 构建器
     */
    private ThreadPoolSet() {
        poolSet = new HashMap<>();
    }
    /**
     * 取得线程池的集合的实例
     * @return ThreadPoolSet
     */
    public static synchronized ThreadPoolSet getInstance() {
        if (instance == null) {
            instance = new ThreadPoolSet();
            instance.addThreadPool(poolKind.danMuThreadPool, Executors.newFixedThreadPool(3));
        }
        return instance;
    }

    /**
     * 通过名字取得集合中线程池
     * @param kind
     * @return ExecutorService
     */
    public ExecutorService getThreadPool(poolKind kind) {
        return poolSet.get(kind);
    }

    /**
     * 添加线程池到集合
     * @param kind
     * @param poolService
     */
    public void addThreadPool(poolKind kind, ExecutorService poolService) {
        poolSet.put(kind, poolService);
    }



}
